# Maintainer: Rémy Oudompheng <remy@archlinux.org>

pkgname=texlive-pictures
pkgver=2018.48511
_revnr=${pkgver#2018.}
pkgrel=1
pkgdesc="TeX Live - Packages for drawings graphics"
license=('GPL')
arch=(any)
depends=('texlive-core')
groups=('texlive-most')
url='http://tug.org/texlive/'
source=("https://sources.archlinux.org/other/texlive/$pkgname-$pkgver-src.zip"
        "$pkgname.maps"
        "xypdf-rev1.21.patch")
options=('!emptydirs')
sha256sums=('9735c6b6c656d91f7992d45cee312e75b2b7a950ba7e62675a7e493fbd08f5f5'
            '847676e2322065219992ef249a68cddb26d71e192e8d59db58f264c5e11c8be9'
            '4e5cedf4775542461b442c06bdabb3eb4e20a04f54e493bc753a958577e78175')

build() {
   cd "$srcdir"
   for p in *.tar.xz; do
	   bsdtar -xf $p
   done
   rm -rf {tlpkg,doc,source} || true

   patch -Np1 -i "${srcdir}/xypdf-rev1.21.patch" -d "${srcdir}/tex/generic/xypic"
}

package() {
   cd "$srcdir"
   install -m755 -d $pkgdir/var/lib/texmf/arch/installedpkgs
   sed -i '/^#/d' CONTENTS
   install -m644 CONTENTS $pkgdir/var/lib/texmf/arch/installedpkgs/${pkgname}_${_revnr}.pkgs
   install -m644 $pkgname.maps $pkgdir/var/lib/texmf/arch/installedpkgs/
   install -m755 -d $pkgdir/usr/share
   wanteddirs=$(for d in *; do test -d $d && [[ $d != texmf* ]] && echo $d; done) || true
   for dir in $wanteddirs; do
     find $dir -type d -exec install -d -m755 $pkgdir/usr/share/texmf-dist/'{}' \;
     find $dir -type f -exec install -m644 '{}' $pkgdir/usr/share/texmf-dist/'{}' \;
   done
   if [[ -d texmf-dist ]]; then
     find texmf-dist -type d -exec install -d -m755 $pkgdir/usr/share/'{}' \;
     find texmf-dist -type f -exec install -m644 '{}' $pkgdir/usr/share/'{}' \;
   fi
   if [[ -d $pkgdir/usr/share/texmf-dist/scripts ]]; then
     find $pkgdir/usr/share/texmf-dist/scripts -type f -exec chmod a+x '{}' \;
   fi

    _linked_scripts="
cachepic/cachepic.tlu
epspdf/epspdftk.tcl
epspdf/epspdf.tlu
fig4latex/fig4latex
getmap/getmapdl.lua
mathspic/mathspic.pl
mkpic/mkpic
petri-nets/pn2pdf
"
    install -m755 -d $pkgdir/usr/bin
    for _script in ${_linked_scripts}; do
        _scriptbase=$(basename $_script)
        _scriptbase=${_scriptbase%.*}
        ln -s /usr/share/texmf-dist/scripts/${_script} ${pkgdir}/usr/bin/${_scriptbase}
    done
}
